<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>大西信息科技有限公司</title>
	<link rel="icon" href="../static/img/favicon.ico" type="image/x-icon" >
    <link rel="stylesheet" href="static/css/common.css">
    <link rel="stylesheet" href="static/css/messageLogin.css">
	<!--[if IE]> 
    <link rel="stylesheet" href="static/css/loginie.css">
	<![endif]-->


</head>
<body onkeydown="KeyDown()">
    <div class="header">
		<div class="ie">
			<img src="static/img/logo @2x.png" alt="">
			<p>中铁十二局集团第一工程有限公司</p>
		</div>
    </div>
    <form action="" method="post" class="login">
        <p class="name">登   录</p>
        <p class="loginType">
            <a href="login.html" id="psd"><span>密码登录</span></a>
            <a href="messageLogin.html" id="mes"><span>短信登录</span></a>
            <a href="qrcode.html" id="sao"><span>扫码登录</span></a>
        </p>
        <p class="phone" id="phone_get">
            <span></span>
            <span></span>
            <input type="text" placeholder="手机号" id="phone_number" autocomplete="off">
            <button type="button" id="send" class="sendMessage">获取验证码</button>
        </p>
        <!-- <span class="errPhone">手机号码有误</span> -->
        <p class="phone mess" id="phone_mess">
            <span></span>
            <span></span>
            <input type="text" placeholder="短信验证码" id="message" autocomplete="off" >
        </p>
        <span class="err">验证码有误</span>
        <button class="sub" type="button" id="mesSub">登 录</button>
		<p class="center"><a href="regist1.html">还没账号？<span style="color: #075A8F;">去注册</span></a></p>
    </form>
    <div class="footer">
        <p class="dx">
			<a href="https://www.daxiit.com" target="_blank">西安大西信息科技有限公司 ©2019 </a>
			<a href="http://www.beian.miit.gov.cn" target="_blank" style="margin-left:10px;">陕ICP备15006746号</a>
		</p>
    </div>
</body>
</html>
<script src="../static/js/jquery-1.8.3.js"></script>
<script src="../static/dx.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/js/input.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function(){
	// 获取验证码
	$('#send').click(function(){
		var phone = $('#phone_number').val();
		var isNall = DX.isNull(phone);
		if(isNall){$('.err').show();$('.err').html('手机号不能为空');return;}
		var result = DX.verPhone(phone);
		if(!result){$('.err').show();$('.err').html('手机号格式不正确');return;}
		var second = 60;
		
		
		
		// 发送验证码
		DX.ajax_method({
			'type':'POST',
			'url':'/user/login/sendSms',
			'param':{'phone':phone,'loginVerify':true},
			'callBack':function(res){
				$('.err').hide();
				if(res.code == '200'){
					var time =setInterval(function(){
						if(second == 0){
							$('#send').html("获取验证码");
							$('#send').attr('disabled',false);
							clearInterval(time);
						}else{
							$('#send').html("重新发送(" + second + ")");
							$('#send').attr('disabled',true);
							second--;
						}
						
					},1000);
					
				}else{
					$('.err').show();
					$('.err').html('');
					$('.err').html(res.msg);
				}
			}
		})
		
	})
	
	// 验证码登录
	$('#mesSub').click(function(){
		login();
	})
	
	// 点击选中
	$("#phone_number").focus(function(){$('.username').addClass('active');})
	$('#phone_number').blur(function(){$('.username').removeClass('active');})
	$("#message").focus(function(){$('.password').addClass('active');})
	$('#message').blur(function(){$('.password').removeClass('active');})
    
});

// enter登录
	function KeyDown()
	{
		// console.log(event.keyCode);
		if (event.keyCode == 13){
			event.returnValue=false;
			event.cancel = true;
			login();
		}
	}
	// login
	function login(){
		var phone = $('#phone_number').val();
		var code = $('#message').val();
		var isphone = DX.verPhone(phone);
		if(!isphone){
			$('.err').show();
			$('.err').html();
			$('.err').html('请输入手机号');return;
		};
		var rule = DX.isNull(code);
		if(rule){
			$('.err').show();
			$('.err').html();
			$('.err').html('验证码不能为空');return;
		}
		DX.ajax_method({
			'type':'POST',
			'url':'/user/login/loginWithPhoneCode',
			'param':{'phone':phone,'verifyCode':code},
			'callBack':function(res){
				$('.err').hide();
				if(res.code == '200'){
					DX.setCookie('token',res.data.Token);
					if(res.data.unitOrProject == "unit"){
						window.location.href='../office.html';
					}else{
						window.location.href='../index.html';	
					}
				}else{
					$('.err').show();
					$('.err').html();
					$('.err').html(res.msg);
				}
				
			}
		})
	}
</script>